package org.lds.scheduled.job.admin.business.job.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lds.scheduled.job.admin.business.job.model.request.*;
import org.lds.scheduled.job.admin.business.job.model.response.*;
import org.lds.scheduled.job.admin.business.job.service.JobBaseService;
import org.lds.scheduled.job.common.model.dto.ResultDTO;
import org.lds.scheduled.job.common.model.db.OrderBy;
import org.lds.scheduled.job.common.model.db.PageResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common/job")
public class JobBaseController {
    private final JobBaseService jobBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<JobBaseResponse> createJob(@RequestBody @Validated JobBaseCreateRequest request) {
        return jobBaseService.createJob(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<JobBaseBatchCreateResponse> batchCreateJob(@RequestBody @Validated JobBaseBatchCreateRequest request) {
        return jobBaseService.batchCreateJob(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<JobBaseDeleteResponse> deleteJob(@RequestBody JobBaseDeleteRequest request) {
        return jobBaseService.deleteJob(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<JobBaseBatchDeleteResponse> batchDeleteJob(@RequestBody @Validated JobBaseBatchDeleteRequest request) {
        return jobBaseService.batchDeleteJob(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<JobBaseResponse> updateJob(@RequestBody @Validated JobBaseUpdateRequest request) {
        return jobBaseService.updateJob(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<JobBaseBatchUpdateResponse> batchUpdateJob(@RequestBody @Validated JobBaseBatchUpdateRequest request) {
        return jobBaseService.batchUpdateJob(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<JobBaseListResponse> listJob(@RequestBody JobBaseListRequest request) {
        return jobBaseService.listJob(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<JobBaseListResponse> listAllJob(@RequestBody OrderBy orderBy) {
        return jobBaseService.listAllJob(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<JobBaseResponse> getJobById(@RequestBody @Validated JobBaseGetByIdRequest request) {
        return jobBaseService.getJobById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<JobBaseListResponse> getJobByIds(@RequestBody @Validated JobBaseGetByIdsRequest request) {
        return jobBaseService.getJobByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<JobBaseResponse>> listJobPage(@RequestBody JobBaseListPageRequest request) {
        return jobBaseService.listJobPage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated JobBaseGetByKeyRequest request) {
        return ResultDTO.success(jobBaseService.getJobByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<JobBaseBatchCreateResponse> batchCreateJobAsync(@RequestBody @Validated JobBaseBatchCreateRequest request) {
        return jobBaseService.batchCreateJobAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<JobBaseBatchDeleteResponse> batchDeleteJobAsync(@RequestBody @Validated JobBaseBatchDeleteRequest request) {
        return jobBaseService.batchDeleteJobAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<JobBaseBatchUpdateResponse> batchUpdateJobAsync(@RequestBody @Validated JobBaseBatchUpdateRequest request) {
        return jobBaseService.batchUpdateJobAsync(request);
    }

}